float4x4 World;
float4x4 View;
float4x4 Projection;

float3 cameraPosition;

struct VertexShaderInput
{
    float4 Position : POSITION0;
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;
    float4 Position2D : TEXCOORD0;
	float CamDistance : TEXCOORD1;
};

struct PixelShaderOutput
{
    float4 Color : COLOR0;
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;

    float4 worldPosition = mul(input.Position, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);
	output.Position2D = output.Position;

	float dist = distance(cameraPosition, worldPosition);
    output.CamDistance = dist;

    return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
	PixelShaderOutput output;
	output.Color.r = input.CamDistance;
	output.Color.g = 0;
	output.Color.b = 0;
	output.Color.a = 1;
    return output.Color;
}

technique Technique1
{
    pass Pass1
    {
        VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 PixelShaderFunction();
    }
}
